var xAxis_leftCenter= [];
var data1_leftCenter = [];
var data2_leftCenter = [];
var Obj_leftCenter=[],leftcenterNewdata,leftcenterNewdata2=[];
var Arr_leftCenter,quarter=[],quarterLength;
var moneyAll=0,peopleAll=0,grant_year;
var yearNow,monthNow,newProdata,obj;
var setSize_leftCenter=15;
// var oneDay_base_leftbottom = 24 * 3600 * 1000 * 30;
var leftCenterParam=JSON.stringify({
    'top':'5'
})
var leftCenterDate=JSON.stringify({
    'year':new Date().getFullYear()
})
// console.log(leftCenterDate);
//县金额，人数增幅情况(时间)
var myChart3 = echarts.init(document.getElementById('map1-b'));
startLeftCenter();
function dataAvl(quarter){  
    for(var a=0;a<8;a++){
       for(var b=0;b<3;b++){
            grant_year=Arr_leftCenter[3*a+b].grant_year;
            moneyAll+=Number(Arr_leftCenter[3*a+b].total_capital);
            peopleAll+=Number(Arr_leftCenter[3*a+b].total_person);
       }
        xAxis_leftCenter.push(grant_year+'年'+Arr_leftCenter[3*a].grant_month+'-'+Arr_leftCenter[3*a+2].grant_month+'月');
       quarter.push({
            year:grant_year,
            people:peopleAll,
            money:moneyAll
       })
       moneyAll=0,peopleAll=0;
    }
    return quarter
}
function startLeftCenter() {  
    $.ajax({
        type: "POST",
        // url: baseurl+"county/listpersoncapital",
        url:baseurl+"county/indexAmplification",
     dataType: "json",
        data:leftCenterDate,
        contentType:'application/json',
        success: function (result) {
        //   console.log(result);
            Arr_leftCenter=result;
            xAxis_leftCenter=[];
            Obj_leftCenter=[];
            data1_leftCenter=[],data2_leftCenter=[];
            quarterLength=Arr_leftCenter.length/3;
            quarter=[];
            moneyAll=0,peopleAll=0;
            // console.log(quarterLength);
            dataAvl(quarter);
            // console.log(quarter);
            // $.each(Arr_leftCenter,function(i,n){
            //     xAxis_leftCenter.push(n.grant_year);
            // });
        //  console.log(xAxis_leftCenter)
            // xAxis_leftCenter=[...new Set(xAxis_leftCenter)];

            // xAxis_leftCenter.forEach(function (el, index){
            //     var moneyAll=0,peopleAll=0;
            //     // console.log(el)
            //     Arr_leftCenter.forEach(function (el1, index1){
            //         // console.log(el1)
            //         if(el == el1.grant_year){
            //             moneyAll +=Number(el1.total_capital);
            //             peopleAll +=Number(el1.total_person);
            //         }
            //     })
            //     Obj_leftCenter.push({
            //         grant_year:el,
            //         people:peopleAll,
            //         money:moneyAll
            //     })       
            // })
    //       console.log(Obj_leftCenter);
            $.each(quarter,function(i,n){
                data1_leftCenter.push((parseInt(n.people)/10000).toFixed(3))
            })
            $.each(quarter,function(i,n){
                data2_leftCenter.push((parseInt(n.money)/10000).toFixed(4))
            })
            // console.log(data1_leftCenter)
            // console.log(data2_leftCenter)
            myChart3.setOption({
                xAxis:[{
                    data:xAxis_leftCenter,
                    axisLabel:{
                        fontSize:setSize_leftCenter,
                        formatter:(params)=>{
                            var xAxis_data=params.split('年');
                            var data_xAixs=''+xAxis_data[0]+'年'+'\n'+''+xAxis_data[1]+'';
                            return data_xAixs
                        }
                    },
                }],
                yAxis:[{
                    axisLabel:{
                        fontSize:yAxisSize
                    }
                }],
                series: [
                    {
                        symbolSize:symbolAll,
                        name:'人数(万)',
                        type:'line',
                        data:data1_leftCenter
                    },
                    {
                        symbolSize:symbolAll,
                        name:'总金额(万)',
                        type:'line',
                        yAxisIndex: 1,
                        data:data2_leftCenter
                    }
                ]
            });
            myChart3.hideLoading();
        },
        error:function(XMLHttpRequest,info){
            // console.log(info)
        }
    });
}
//地区点击
function dataYear(countyClick){
    $.ajax({
        type: "POST",
        url: baseurl+"county/amplificationCounty",
        dataType: "json",
        data:countyClick,
        contentType:'application/json',
        success: function (result) {
        //   console.log(result);
            xAxis_leftCenter=[];
            Arr_leftCenter='';
            Arr_leftCenter=result;
            Obj_leftCenter=[];
            data1_leftCenter=[],data2_leftCenter=[];
            quarterLength=Arr_leftCenter.length/3;
            quarter=[];
            moneyAll=0,peopleAll=0;
            // console.log(quarterLength);
            dataAvl(quarter);
            // console.log(quarter);
            // $.each(Arr_leftCenter,function(i,n){
            //     xAxis_leftCenter.push(n.grant_year);
            // });
        //  console.log(xAxis_leftCenter);
            // xAxis_leftCenter=[...new Set(xAxis_leftCenter)];
            // console.log(xAxis_leftCenter);
            // var xAxis_firstDate=date_xAxis[0].split('/').join(',');
            // var firstDate= +new Date(xAxis_firstDate);
            // console.log(xAxis_firstDate)//设置初始时间
            // firstDate.setFullYear(xAxis_firstDate);
            // for (var i = 0; i < 25; i++) {
            //     var now = new Date(firstDate += oneDay_base_leftbottom);
            //     xAxis_leftCenter_.push([now.getFullYear(), now.getMonth()+1].join('/'));
            // }
            // xAxis_leftCenter.forEach(function (el, index){
            //     var moneyAll=0,peopleAll=0;
            //     // console.log(el)
            //     Arr_leftCenter.forEach(function (el1, index1){
            //         // console.log(el1)
            //         if(el == el1.grant_year){
            //             moneyAll +=Number(el1.total_capital);
            //             peopleAll +=Number(el1.total_person);
            //         }
            //     })
            //     Obj_leftCenter.push({
            //         grant_year:el,
            //         people:peopleAll,
            //         money:moneyAll
            //     })       
            // })
    //       console.log(Obj_leftCenter);
            $.each(quarter,function(i,n){
                data1_leftCenter.push((parseInt(n.people)/10000).toFixed(3))
            })
            $.each(quarter,function(i,n){
                data2_leftCenter.push((parseInt(n.money)/10000).toFixed(4))
            })
            // console.log(data1_leftCenter)
            // console.log(data2_leftCenter)
            myChart3.setOption({
                xAxis:[{
                    data:xAxis_leftCenter,
                }],
                series: [
                    {
                        name:'人数(万)',
                        type:'line',
                        data:data1_leftCenter
                    },
                    {
                        name:'总金额(万)',
                        type:'line',
                        yAxisIndex: 1,
                        data:data2_leftCenter
                    }
                ]
            });
            myChart3.hideLoading();
        },
        error:function(XMLHttpRequest,info){
            // console.log(info)
        }
    });
}
//项目点击
function dataProyear(proClick){
    $.ajax({
        type: "POST",
        url: baseurl+"county/amplificationProject",
        //  dataType: "json",
        data:proClick,
        contentType:'application/json',
        success: function (result) {
        //   console.log(result);
            xAxis_leftCenter=[];
            Arr_leftCenter=[];
            Arr_leftCenter=result;
            Obj_leftCenter=[];
            leftcenterNewdata=[];
            leftcenterNewdata2=[];
            data1_leftCenter=[],data2_leftCenter=[];
            quarter=[];
            moneyAll=0,peopleAll=0;
            $.each(Arr_leftCenter,function(i,n){
                leftcenterNewdata2.push({
                    grant_year:n.grant_year,
                    total_capital:n.total_capital,
                    total_person:n.total_person,
                    grant_month:n.grant_month,
                })
            })
            // console.log(leftcenterNewdata2);
            if(leftcenterNewdata2.length<24){
                quarterLength=24-leftcenterNewdata2.length;
                for(var e=0;e<quarterLength;e++){
                    leftcenterNewdata2.push({
                        grant_year:"",
                        total_capital:'',
                        total_person:'',
                        grant_month:"",
                    })
                }
                // console.log(leftcenterNewdata2);
                for(var d=0;d<24;d++){
                    if(d<12){
                        yearNow=new Date().getFullYear()-2;
                        monthNow=Number(d+1);
                    }else{
                        yearNow=new Date().getFullYear()-1;
                        monthNow=Number(d-11);
                    }
                    leftcenterNewdata.push({
                        grant_year:""+yearNow+"",
                        total_capital:'',
                        total_person:'',
                        grant_month:""+monthNow+"",
                    })
                }
                leftcenterNewdata.forEach(function(i,n){
                    leftcenterNewdata2.map(function(e,n){
                        if(i.grant_year===e.grant_year && i.grant_month===e.grant_month){
                            i.grant_year= i.grant_year;
                            i.grant_month=i.grant_month;
                            i.total_capital=e.total_capital;
                            i.total_person=e.total_person;
                        }
                    })
                }) 
                Arr_leftCenter=leftcenterNewdata;
            }
            // console.log(Arr_leftCenter);
            dataAvl(quarter);
            // console.log(quarter);
            // $.each(Arr_leftCenter,function(i,n){
            //     xAxis_leftCenter.push(n.grant_year);
            // });
            //  console.log(xAxis_leftCenter);
            // xAxis_leftCenter=[...new Set(xAxis_leftCenter)];
            // xAxis_leftCenter.forEach(function (el, index){
            //     var moneyAll=0,peopleAll=0;
            //     // console.log(el)
            //     Arr_leftCenter.forEach(function (el1, index1){
            //         // console.log(el1)
            //         if(el == el1.grant_year){
            //             moneyAll +=Number(el1.total_capital);
            //             peopleAll +=Number(el1.total_person);
            //         }
            //     })
            //     Obj_leftCenter.push({
            //         grant_year:el,
            //         people:peopleAll,
            //         money:moneyAll
            //     })       
            // })
            // console.log(Obj_leftCenter);
            $.each(quarter,function(i,n){
                data1_leftCenter.push((parseInt(n.people)/10000).toFixed(3))
            })
            $.each(quarter,function(i,n){
                data2_leftCenter.push((parseInt(n.money)/10000).toFixed(4))
            })
            // console.log(data1_leftCenter)
            // console.log(data2_leftCenter)
            myChart3.setOption({
                xAxis:[{
                    data:xAxis_leftCenter,
                }],
                series: [
                    {
                        name:'人数(万)',
                        type:'line',
                        data:data1_leftCenter
                    },
                    {
                        name:'总金额(万)',
                        type:'line',
                        yAxisIndex: 1,
                        data:data2_leftCenter
                    }
                ]
            });
            myChart3.hideLoading();
        },
        error:function(XMLHttpRequest,info){
            // console.log(info)
        }
    });
}


var option3 = {
    tooltip: {
    	show:true,
        trigger: 'axis',
        position: function (pt) {
            return [pt[0], '10%'];
        },
        position:'left',
        formatter:(parms) => {
//          console.log(parms);
            var span="<span style='display:inline-block;margin-right:5px;border-radius:10px;width:"+hoverSize+"px;height:"+hoverSize+"px;background-color:#c23531;'></span>"
            var span2="<span style='display:inline-block;margin-right:5px;border-radius:10px;width:"+hoverSize+"px;height:"+hoverSize+"px;background-color:#2f4554;'></span>"
            let data ="<div class='leftCenter_hover'>"+
            "<p>"+parms[0].axisValueLabel+"</p>"+
            "<p>"+span+"人数(万):"+""+parms[0].data+""+"</p>"+
            "<p>"+span2+"总金额(万):"+""+parms[1].data+""+"</p>"+
            "</div>"
            return data;
        }
    },
    grid: {
        left: '12%',
        right: '5%',
        bottom: '5%',
        containLabel: true
    },
    xAxis: {
        axisLabel:{
            interval : 0, 
            textStyle: {
                color: '#fff'
            },
            fontSize:setSize_leftCenter,
        },
        splitLine: {
            show: false
        },
        nameTextStyle:{
            color:"#fff"
        },
        type: 'category',
        boundaryGap: false,
        data: []   
    },
    yAxis: [
        {
            splitLine: {
                show: false
            },
            type: 'value',
            // name: '人数(晚人)',
            nameTextStyle:{
                color:"#fff"
            },
            color:"#fff",
            min: 0,
            interval: 50,
            axisLabel: {
//          	show:false,
                formatter: '{value}',
                 color: '#fff',
                 fontSize:15,
            }
        }
        ,
        {
            show:false,
            splitLine: {
                show: false
            },
            type: 'value',
            // name: '总金额(千万)',
            nameTextStyle:{
                color:"#fff"
            },
            color:["#fff"],
            min: 0,
            interval: 15000,
            axisLabel: {
                show:false,
                formatter: '{value}',
                color: '#999',
                 fontSize:5
            }
        }
    ],
    dataZoom: [{
        show:false,
        type: 'inside',
        start: 0,
        end: 100
    }
    , {
        show:false,
        type: 'inside',
        start: 0,
        end: 100,
    }
],
    series: [
        {
        /** 
         * 渐变的实现 
        设置itemStyle的color为new echarts.graphic.LinearGradient()线性渐变即可.
        这个API在官方文档里面都没找到, 
        经过测试前四个参数设置为0, 0, 1, 0可以从左到右渐变.
         设置为0,0,0,1可以从上到下渐变.
         第5个参数数组表示开始的颜色和结束的颜色.
        */
        areaStyle: {
            normal: {
                opacity:1,
                	color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: '#00f7fe'
                    }, 
                    {
                        offset: 1,
                        color: '#e6d69e'
                    }]
                ) 
            }
        },
        smooth: true,
        name:'人数',
        type:'line',
        data:[],
         lineStyle:{
        	color:new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                offset: 0,
                color: '#00f7fe'
            }, 
            {
                offset: 1,
                color: '#e6d69e'
            }]
        ) 
        }
        },
        {
	        areaStyle: {
	            normal: {
	                opacity:1,
	                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
	                        offset: 0,
	                        color: '#e6d69e'
	                    }, 
	                    {
	                        offset: 1,
	                        color: '#e5585d'
	                    }]
	                ) 
	            }
	        },
	        smooth: true,
	        name:'总金额',
	        type:'line',
            yAxisIndex: 1,
	        data:[],
	        lineStyle:{
	        	color:new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                    offset: 0,
                    color: '#e6d69e'
                }, 
                {
                    offset: 1,
                    color: '#e5585d'
                }]
            ) 
	        }
        },
    ]
};
function functionTitle(dataCounty_time){
    var titelName = dataCounty_time.title;
    return titelName;
}
myChart3.setOption(option3);